package com.mes.cloud.controller;

import com.github.pagehelper.PageInfo;
import com.mes.cloud.dto.BmeBcDigitalDTO;
import com.mes.cloud.service.BmeBcDigitalService;
import com.mes.cloud.util.CommPager;
import com.mes.cloud.util.JSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * <bme_bc_digital基础表>
 *
 * @author xhy
 * @version 1.0
 * @date 2019/06/11 16:00
 */
@Api(tags = "BmeBcDigitalController", description = "BC Digitization")
@RestController
@RequestMapping("/bmeBcDigital")
public class BmeBcDigitalController {
    private static final Logger LOGGER = LoggerFactory.getLogger(BmeBcDigitalController.class);

    @Autowired
    private BmeBcDigitalService bmeBcDigitalService;

    /**
     * <根据条件获取bme_bc_digital基础表列表>
     *
     * @param map
     * @return
     * @author xhy
     * @date 2019/06/11 16:00
     */
    @ApiOperation(value = "列表 无分页")
    @RequestMapping(value = "/findList", method = RequestMethod.POST)
    public JSONResult findList(@RequestBody @NotNull Map<Object, Object> map) {
        LOGGER.info("Class BmeBcDigitalController:Method findList :inParam map: {}", map.toString());
        JSONResult result = JSONResult.success(bmeBcDigitalService.findList(map));
        LOGGER.info("Class BmeBcDigitalController:Method findList :OutParam jsonResult: {}", result);
        return result;
    }

    /**
     * <根据条件获取bme_bc_sub基础表列表>
     *
     * @param map
     * @return
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "列表 无分页")
    @RequestMapping(value = "/findListByBcCode", method = RequestMethod.POST)
    public JSONResult findListByBcCode(@RequestBody Map<Object, Object> map) {
        JSONResult result;
        try {
            result = JSONResult.success(bmeBcDigitalService.findListByBcCode(map));
        } catch (Exception e) {
            LOGGER.error(e.getMessage());
            result = JSONResult.fail(201, e.getMessage());
        }
        return result;
    }

    /**
     * <根据条件获取bme_bc_digital基础表分页列表>
     *
     * @param map
     * @return JSONResult
     * @author xhy
     * @date 2019/06/11 16:00
     */
    @ApiOperation(value = "列表 分页")
    @RequestMapping(value = "/findPageList", method = RequestMethod.POST)
    public JSONResult findPageList(@RequestBody @NotNull Map<Object, Object> map) {
        LOGGER.info("Class BmeBcDigitalController:Method findPageList :inParam map: " + map.toString());
        CommPager<BmeBcDigitalDTO> pageInfo = bmeBcDigitalService.findPageList(map);
        LOGGER.info("Class BmeBcDigitalController:Method findPageList :outParam map: {}", pageInfo);
        JSONResult result = JSONResult.success(pageInfo);
        return result;
    }

    /**
     * <获取bme_bc_digital基础表的最大记录数>
     *
     * @param map
     * @return JSONResult
     * @author xhy
     * @date 2019/06/11 16:00
     */
    @ApiOperation(value = "获取最大记录数")
    @RequestMapping(value = "/getBmeBcDigitalCount", method = RequestMethod.POST)
    public JSONResult getBmeBcDigitalCount(@RequestBody @NotNull Map<Object, Object> map) {
        JSONResult result = JSONResult.success("", 200, "");
        return result;
    }

    /**
     * <新增bme_bc_digital基础表>
     *
     * @param
     * @return JSONResult
     * @author xhy
     * @date 2019/06/11 16:00
     */
    @ApiOperation(value = "新增")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JSONResult insert(@RequestBody @NotNull BmeBcDigitalDTO bmeBcDigitalDTO) {
        LOGGER.info("Class BmeBcDigitalController:Method update :inParam bmeBcDigitalDTO: {}", bmeBcDigitalDTO);
        long count = bmeBcDigitalService.insert(bmeBcDigitalDTO);
        if (count < 1) {
            return JSONResult.fail(201, "操作失败");
        }
        LOGGER.info("Class BmeBcDigitalController:Method update :outParam count: {}", count);
        JSONResult result = JSONResult.success();
        return result;
    }

    /**
     * <更新bme_bc_digital基础表>
     *
     * @param
     * @return JSONResult
     * @author xhy
     * @date 2019/06/11 16:00
     */
    @ApiOperation(value = "更新")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public JSONResult update(@RequestBody @NotNull BmeBcDigitalDTO bmeBcDigitalDTO) {
        LOGGER.info("Class BmeBcDigitalController:Method update :inParam bmeBcDigitalDTO: {}", bmeBcDigitalDTO);
        long count = bmeBcDigitalService.update(bmeBcDigitalDTO);
        if (count < 1) {
            return JSONResult.fail(201, "操作失败");
        }
        JSONResult result = JSONResult.success();
        LOGGER.info("Class BmeBcDigitalController:Method update :outParam count: {}", count);
        return result;
    }

    @ApiOperation(value = "删除")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public JSONResult delete(@RequestBody BmeBcDigitalDTO digitalDTO) {
        LOGGER.info("Class BmeBcDigitalController:Method delete :inParam digitalDTO: {}", digitalDTO);
        long count = bmeBcDigitalService.delete(digitalDTO.getId());
        if (count < 1) {
            return JSONResult.fail(201, "操作失败");
        }
        JSONResult result = JSONResult.success();
        LOGGER.info("Class BmeBcDigitalController:Method update :outParam count: {}", count);
        return result;
    }

    /**
     * <根据bme_bc_digital基础表标识获取bme_bc_digital基础表>
     *
     * @param
     * @return JSONResult
     * @author xhy
     * @date 2019/06/11 16:00
     */
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    public JSONResult get(@RequestBody @NotNull BmeBcDigitalDTO bmeBcDigitalDTO) {
        LOGGER.info("Class BmeBcDigitalController:Method get :inParam bmeBcDigitalDTO: {}", bmeBcDigitalDTO);
        BmeBcDigitalDTO bmeBcDigitalDTO1 = bmeBcDigitalService.get(bmeBcDigitalDTO.getId());
        LOGGER.info("Class BmeBcDigitalController:Method get :outParam bmeBcDigitalDTO: {}", bmeBcDigitalDTO1);
        JSONResult result = JSONResult.success(bmeBcDigitalDTO1);
        return result;
    }



    /**
     * <根据bme_bc_digital基础表标识获取bme_bc_digital基础表>
     *
     * @param map
     * @return long
     * @author xhy
     * @date 2019/05/09 16:00
     */
    @ApiOperation(value = "启用禁用")
    @RequestMapping(value = "/enable", method = RequestMethod.POST)
    public JSONResult enable(@RequestBody Map<Object, Object> map) {
        LOGGER.info("Class BmeBcDigitalController:Method updateEnable :inParam map: " + map);
        JSONResult jsonResult = null;
        try {
            long count = bmeBcDigitalService.enable(map);
            if (count > 0) {
                jsonResult = JSONResult.success();
            } else {
                jsonResult = JSONResult.fail(201, "操作失败");
            }
        } catch (Exception e) {
            LOGGER.error("Class BmeBcDigitalController:Method updateEnable :inParam e: " + e.getMessage());
            jsonResult = JSONResult.fail(201, e.getMessage());
        }
        LOGGER.info("Class BmeBcDigitalController :Method updateEnable :OutParam jsonResult: " + jsonResult);
        return jsonResult;
    }



}
